unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, frxClass, StdCtrls, frxDesgn;

type
  TStud=class(TObject)
  public
    Name:string;
    Agex:Integer;
    List:TStringList;
  constructor Create;  
  end;
  
  TForm1 = class(TForm)
    frxrprt1: TfrxReport;
    frxUserDataSet1: TfrxUserDataSet;
    frxUserDataSet2: TfrxUserDataSet;
    Btnx_3: TButton;
    Btnx_1: TButton;
    frxDesigner1: TfrxDesigner;
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_3Click(Sender: TObject);
    procedure frxUserDataSet1GetValue(const VarName: String;
      var Value: Variant);
    procedure frxUserDataSet2GetValue(const VarName: String;
      var Value: Variant);
  private
    FListStud:TStringList;
    FActvStud:TStud;
  protected
    procedure PrepareData;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Btnx_1Click(Sender: TObject);
begin
  frxrprt1.LoadFromFile('00001.fr3');
  frxrprt1.DesignReport();
end;

{ TStud }

constructor TStud.Create;
begin
  List:=TStringList.Create;
end;

procedure TForm1.PrepareData;
var
  I,M:Integer;
  StudA:TStud;
begin
  FListStud:=TStringList.Create;

  for I:=0 to 11 do
  begin
    StudA:=TStud.Create;
    StudA.Name:=Format('Name%D',[I]);
    StudA.Agex:=I+19;

    for M:=1 to Random(10)+1 do
    begin
      StudA.List.Add(Format('%S.Math=%D',[StudA.Name,Random(100)]))
    end;
    FListStud.AddObject('',StudA);    
  end;



  FActvStud:=TStud(FListStud.Objects[0]);
end;


procedure TForm1.Btnx_3Click(Sender: TObject);
begin
  PrepareData;
  
  frxUserDataSet1.RangeEnd     :=reCount;
  frxUserDataSet1.RangeEndCount:=FListStud.Count;

  frxUserDataSet2.RangeEnd     :=reCount;
  frxUserDataSet2.RangeEndCount:=FActvStud.List.Count;
  
  frxrprt1.LoadFromFile('00001.fr3');
  frxrprt1.ShowReport();
end;

procedure TForm1.frxUserDataSet1GetValue(const VarName: String;
  var Value: Variant);
begin
  FActvStud:=TStud(FListStud.Objects[frxUserDataSet1.recNo]);
  if FActvStud=nil then Exit;
  if VarName='Name' then Value:=FActvStud.Name;
  if VarName='AgeX' then Value:=FActvStud.Agex;

  frxUserDataSet2.RangeEnd     :=reCount;
  frxUserDataSet2.RangeEndCount:=FActvStud.List.Count;  
end;

procedure TForm1.frxUserDataSet2GetValue(const VarName: String;
  var Value: Variant);
begin
  if FActvStud<>nil then
  begin
    if FActvStud.List.Count>0 then
    begin
      if VarName='Math' then Value:=FActvStud.List.Strings[frxUserDataSet2.RecNo];
    end;
  end;
end;

end.
